﻿Public Class ucoperationsetting
    Implements IConfHolder
    Private opconf As OperationConfig
    Private sopconf As OperationConfig
    Private verrs As String
    Public Function applyConfig() As Boolean Implements IConfHolder.applyConfig
        copySetting()
        If (Not opconf.checkConfig) Then
            validationerrors = opconf.validationerrors
            Return False
        End If
        opconf.writeConfig()
        Return True
    End Function

    Public Sub forcewrite() Implements IConfHolder.forcewrite
        copySetting()
        opconf.writeConfig()
    End Sub

    Public Sub loadConfig() Implements IConfHolder.loadConfig
        opconf = New OperationConfig
        sopconf = New OperationConfig
        displayConfig()
    End Sub
    Private Sub displayConfig()
        chkautorun.Checked = opconf.Autorun
        chkwarning.Checked = opconf.DisplayWarning
        txtimport.Text = opconf.ImportDelay.ToString
        txtretry.Text = opconf.UnsucessfullRetry.ToString
        txtthread.Text = opconf.NumberOfThread.ToString
        chkimock.Checked = opconf.InternalMock
        chkdebug.Checked = opconf.DebugMode
    End Sub
    Private Sub copySetting()
        opconf.Autorun = chkautorun.Checked
        opconf.DisplayWarning = chkwarning.Checked
        opconf.NumberOfThread = commons.toInteger(txtthread)
        opconf.UnsucessfullRetry = commons.toInteger(txtretry)
        opconf.ImportDelay = commons.toInteger(txtimport)
        opconf.DebugMode = chkdebug.Checked
        opconf.InternalMock = chkimock.Checked
    End Sub
    Public Sub revertconfig() Implements IConfHolder.revertconfig
        opconf.Autorun = sopconf.Autorun
        opconf.DisplayWarning = sopconf.DisplayWarning
        opconf.NumberOfThread = sopconf.NumberOfThread
        opconf.UnsucessfullRetry = sopconf.UnsucessfullRetry
        opconf.ImportDelay = sopconf.ImportDelay
        opconf.DebugMode = sopconf.DebugMode
        opconf.InternalMock = sopconf.InternalMock
    End Sub

    Public Property validationerrors As String Implements IConfHolder.validationerrors
        Get
            Return verrs
        End Get
        Set(ByVal value As String)
            verrs = value
        End Set
    End Property

    Private Sub chkdebug_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkdebug.CheckedChanged
        If (chkdebug.Checked) Then
            chkimock.Enabled = True
            Return
        End If
        chkimock.Enabled = False
    End Sub
End Class
